﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Game
{
    /*-------------------------------------------------------------------------
    | Body:
    | ------------
    | 
    |---------------------------------------------------------------------------*/
    public class Body
    {
        private IDK.SceneNode mSceneNode;
        private IDK.SceneNode.Transformation mSceneNodeTranformation; //warning: cache

        public Body(IDK.SceneNode node)
        {
            SceneNode = node;
            IsKinematic = false;
        }

        public bool IsKinematic
        {
            get;
            set;
        }

        public IDK.Vector3 PivotPosition
        {
            get;
            set;
        }

        public IDK.SceneNode SceneNode
        {
            get { return mSceneNode; }
            set
            {
                mSceneNodeTranformation = (mSceneNode = value).GetTransformation();
            }
        }

        public virtual void Rotate(IDK.Quaternion q)
        {
            mSceneNodeTranformation.Rotate(q);
        }

        public virtual void Collision(bool enable)
        {
            throw new NotImplementedException();
        }

        public virtual void LookAtPoint(IDK.Vector3 point)
        {
            throw new NotImplementedException();
           //TODO: calc diection = p2 - p2
          //   mSceneNodeTranformation.(IDK.Quaternion.RotationTo(mSceneNodeTranformation.GetWorldPosition(), point));
        }

        public virtual IDK.Vector3 GetPosition()
        {
            return mSceneNodeTranformation.GetLocalPosition();
        }

        public IDK.Quaternion GetOrientation()
        {
            return mSceneNodeTranformation.GetLocalOrientation();
        }

        public void Translate(IDK.Vector3 step)
        {
            SetPosition(GetPosition() + step);
        }

        public virtual void OnUpdate(Events.ProcessSceneUpdate evnt)
        {
        }

        public virtual void Reset()
        {
        }

        public virtual void SetPosition(IDK.Vector3 pos)
        {
            mSceneNodeTranformation.SetLocalPosition(pos);
        }

        public virtual void AddLocalForce(IDK.Vector3 pos)
        {
            throw new NotImplementedException();
        }

        public virtual void AddLocalImpulse(IDK.Vector3 pos)
        {
            throw new NotImplementedException();
        }

        public virtual void AddWorldForce(IDK.Vector3 pos)
        {
            throw new NotImplementedException();
        }

        public virtual void AddWorldImpulse(IDK.Vector3 pos)
        {
            throw new NotImplementedException();
        }

        public virtual void SetOrientation(IDK.Quaternion q)
        {
            mSceneNodeTranformation.SetLocalOrientation(q);
        }
    }
}
